package com.eddy.service.impl;

import com.eddy.dao.UserDao;
import com.eddy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

//<bean id="userService" class="com.eddy.service.impl.UserServiceImpl">
//@Component("userService")
@Service("userService")
//@Scope("singleton")
//@Scope("prototype")
public class UserServiceImpl implements UserService {
    //<property name="userDao" ref="userDao"></property>
    //@Autowired
    //@Qualifier("userDao")

    @Resource(name="userDao")
    private UserDao userDao;

    /*public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }*/

    //@Value("itcast")
    @Value("${jdbc.driver}")
    private String driver;

    public void show() {
        userDao.show();
        System.out.println("Driver:"+driver);
    }

    //容器创建时
    @PostConstruct
    private void init(){
        System.out.println("init...");
    }
    //容器销毁时
    @PreDestroy
    private void destroy(){
        System.out.println("destroy...");
    }
}
